package logic

import (
	"1-8zy/rpc/shop"
	"context"

	"1-8zy/api/internal/svc"
	"1-8zy/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodAddLogic) GoodAdd(req *types.GoodAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.ShopRpc.GoodAdd(l.ctx, &shop.GoodAddRequest{
		UserId:     int64(req.UserId),
		GoodsTitle: req.GoodsTitle,
		GoodsStock: int64(req.GoodsStock),
		GoodsImage: req.GoodsImage,
		GoodsPrice: float32(req.GoodsPrice),
		GoodsLike:  int64(req.GoodsLike),
		Status:     int64(req.Status),
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}

	return &types.Response{
		Msg:  "添加成功",
		Code: 200,
		Data: add,
	}, nil
}
